|
|
|
|
|
|
|
Tutorial 8
Porting C Header Files |
|
|
|
|
|
|
|
|
Puzzle 29, ''what do you do When It Mega Hurts?" demonstrates how to handle DLL functions that return structures, using the example of the cpuspeed function from Intel's cpuinf32.dll dynamic link library. This library allows you to retrieve all sorts of interesting information about the processors on your PC (at least if you're using Intel processors). |
|
|
|
|
|
|
|
|
This book provides the DLL (on the CD) and sufficient information to demonstrate how to use it in the puzzle. You can obtain the latest version of the DLL and the complete source code for both the DLL and several test programs written in C++ from Intel's Web site at http://developer.intel.com/design/perftool/cpuid/. (Note, I obviously can't guarantee that this file will continue to be available in the future or will remain at the location shown above. Check http://www.desaware.com/ for the latest information in case of changes.) |
|
|
|
|
|
|
|
|
In this tutorial, you'll see how the original C header files were converted into Visual Basic for use by the cputest application. |
|
|
|
|
|
|
|
|
Don't worry, reading this tutorial will not spoil the puzzle. |
|
|
|
|
|
|
|
|
Step 1:
Load the Header File into a Visual Basic Module |
|
|
|
|
|
|
|
|
Consider for a moment the type of information you are likely to find in a Visual Basic standard module: |
|
|
|
|
|
|
|
|
Global variable declarations |
|
|
|
|
|
|
|
|
Definitions of user-defined types (called "structures" in the C/C++ world) |
|
|
|
|
|
|
|
|
Global functions and subroutines |
|
|
|
|
|
|
|
|
Comments explaining the various elements of the module |
|
|
|
|
|
|
|
|
The most important of these are the structure definitions and the function declarations. You can't really access global variables from dynamic link libraries. And although comments are critical for understanding how the module works, there is no functional difference between a comment in VB and one in C/C++. |
|
|
|
|
|